<!DOCTYPE html>
<html>

<head>
  <title>demo</title>
  <script>
    navigator.serviceWorker.register('sw.js')

    async function hello() {
      const name = document.querySelector("#name").value

      const res = await fetch('api/hello', {
        method: 'POST',
        headers: {
          'Content-Type': 'application/json'
        },
        body: JSON.stringify({ name })
      })

      const data = await res.json()

      document.querySelector('#out').innerHTML = JSON.stringify(data)

    }
  </script>
</head>

<body>
  <label for="name">Name: </label><input id="name" value="World">
  <button onclick="hello()">Hello</button>
  <pre id="out"></pre>
</body>

</html>